package day55_322;

import java.util.Arrays;

/**
 * @ClassName Solution
 * @Description TODO
 * @Author clockTown
 * @Date 2021/7/3 20:30
 * @Version 1.0
 */
public class Solution {
    public int coinChange(int[] coins, int amount) {

        if (coins == null || coins.length == 0 || amount <= 0)
            return 0;

        int[] dp = new int[amount + 1];


        Arrays.fill(dp, amount + 1);
        dp[0] = 0;

        for (int coin : coins) {

            for (int i = coin; i <= amount; i++) {

                dp[i] = Math.min(dp[i], 1 + dp[i - coin]);
            }
        }

        return dp[amount] == amount + 1 ? -1 : dp[amount];
    }
}
